local joysp__paoxiao = fk.CreateSkill {

  name = "joysp__paoxiao",

  tags = { Skill.Compulsory, },

}



joysp__paoxiao:addEffect("targetmod", {
  name = "joysp__paoxiao",
  frequency = Skill.Compulsory,
  bypass_times = function(self, player, skill, scope)
    return player:hasSkill(joysp__paoxiao.name) and skill.trueName == "slash_skill" and scope == Player.HistoryPhase
  end,
  bypass_distances = function(self, player, skill, scope)
    return player:hasSkill(joysp__paoxiao.name) and skill.trueName == "slash_skill"
  end,
})

joysp__paoxiao:addEffect(fk.TargetSpecified, {
  name = "#joysp__paoxiao_trigger",
  events = {fk.TargetSpecified},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(joysp__paoxiao.name) and target == player and data.card.trueName == "slash" then
      local times = #player.room.logic:getEventsOfScope(GameEvent.UseCard, 3, function(e)
        local use = e.data[1]
        return use.from == player.id and use.card.trueName == "slash"
      end, Player.HistoryTurn)
      return (times == 2 and data.firstTarget) or times > 2
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local times = #room.logic:getEventsOfScope(GameEvent.UseCard, 3, function(e)
      local use = e.data[1]
      return use.from == player.id and use.card.trueName == "slash"
    end, Player.HistoryTurn)
    if data.firstTarget then
      data.additionalDamage = (data.additionalDamage or 0) + 1
    end
    if times > 2 then
      data.disresponsive = true
      room:addPlayerMark(room:getPlayerById(data.to), fk.MarkArmorNullified)
      data.extra_data = data.extra_data or {}
      data.extra_data.joysp__paoxiao = data.extra_data.joysp__paoxiao or {}
      data.extra_data.joysp__paoxiao[tostring(data.to)] = (data.extra_data.joysp__paoxiao[tostring(data.to)] or 0) + 1
    end
  end,
})
joysp__paoxiao:addEffect(fk.CardUseFinished, {
  refresh_events = {fk.CardUseFinished},
  can_refresh = function(self, event, target, player, data)
    return data.extra_data and data.extra_data.joysp__paoxiao
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    for key, num in pairs(data.extra_data.joysp__paoxiao) do
      local p = room:getPlayerById(tonumber(key))
      if p:getMark(fk.MarkArmorNullified) > 0 then
        room:removePlayerMark(p, fk.MarkArmorNullified, num)
      end
    end
    data.extra_data.joysp__paoxiao = nil
  end,
})

return joysp__paoxiao